/*
 * UserNet  --  TCP/IP implementation in userspace
 * Copyright (C) 2010  Robert Millan
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#include "unet/dev.h"
#include "unet/client.h"
#include "unet/ip.h"

static void
loop_send_packet (int type, const uint8_t mac_addr[ETH_ALEN], struct unet_device *device,
		  const uint8_t *packet, const uint32_t len)
{
  /* Send it back to IP.  */
  unet_ip_incoming_packet (device, packet, len);
}

static int
loop_get_mac (struct in_addr ip_addr __attribute__ ((__unused__)), uint8_t *mac_addr, struct unet_device *device)
{
  memset (mac_addr, 0, ETH_ALEN);
  return 1;
}

static struct unet_client *loop_port_list[2 * 65536];

static struct unet_device loop_device =
  {
    .driver =
    {
      .name = "Loopback",
      .datalink =
      {
	.name = "Loopback",
	.send_packet = loop_send_packet,
	.get_mac = loop_get_mac,
      },
    },
    .port_list = loop_port_list,
  };

void
unet_loop_init ()
{
  unet_device_add (&loop_device);
}
